When your application has finished displaying a sprite animation, you should do the following things in the order shown:
In the sample application, main calls the sample code function DisposeEverything to dispose of sprite-related structures. This function, shown in Listing 0-5 , iterates through the sprites, disposing of each sprite's image data. Then, DisposeEverything calls DisposeSpriteWorld to dispose of the sprite world and all of the sprites in it. Finally, the function calls DisposeGWorld to dispose of the graphics world associated with the sprite world.
Listing 5 Disposing of sprites and the sprite world
// constants
#define kNumSprites 4
#define kNumSpaceShipImages 24
// global variables
SpriteWorld gSpriteWorld = nil;
Sprite gSprites[kNumSprites];
Handle gCompressedPictures[kNumSpaceShipImages];
ImageDescriptionHandle gImageDescriptions[kNumSpaceShipImages];
void DisposeEverything (void)
{
short i;
// dispose of the sprite world and associated graphics world
if (gSpriteWorld)
DisposeSpriteWorld (gSpriteWorld);
// dispose of each sprite's image data
for (i = 0; i < kNumSprites; i++)
{
if (gCompressedPictures[i])
DisposeHandle (gCompressedPictures[i]);
if (gImageDescriptions[i])
DisposeHandle ((Handle)gImageDescriptions[i]);
}
DisposeGWorld (spritePlane);
}
| Previous | Chapter Contents | Chapter Top | Next |